home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / CD Audio Toolkit 1.0 / Source / CDStop.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  7.0 KB  |  268 lines  |  [TEXT/MPS ]

  1. /*
  2.     CDStop - An XFCN to stop at absolute minute, second, block
  3.     ©Apple Computer, Inc. 1988
  4.     All Rights Reserved.
  5.     
  6.     88/10/08    BL°B    First Version
  7.  
  8.     To compile and link this file using Macintosh Programmer's Workshop,
  9.  
  10.     C -q2 CDStop.c
  11.     link -sn Main=CDStop -sn STDIO=CDStop ∂
  12.          -sn INTENV=CDStop -rt XFCN=42 ∂
  13.          -m CDSTOP CDStop.c.o "{CLibraries}"CRuntime.o ∂
  14.          "{CLibraries}"StdCLib.o ∂
  15.          -o HyperCommands
  16.          
  17.     This link directive puts the XCMD in the file "HyperCommands".
  18.     Substitute the name of the stack you want it in.  To move XCMDs
  19.     between stacks, use ResEdit.  They can be in an individual stack,
  20.     the Home stack, the HyperCard application, or the System File.
  21.     
  22. */
  23.  
  24. #include <cd.h>
  25.  
  26. /* prototype definitions for functions */
  27. /* prototype definitions for functions */
  28. void    ExtractBCD(char *, long *);
  29. OSErr    AStop(XCmdBlockPtr, short, long, long, long);
  30. OSErr    ASearch(XCmdBlockPtr, short, short, long, long, long);
  31.  
  32. /* **** WARNING:  DO NOT USE GLOBAL VARIABLES! **** */
  33.  
  34.  
  35. /************************************************************************
  36.  *
  37.  *  Function:        CDStop
  38.  *
  39.  *  Purpose:        Stop absolute minute, second and block
  40.  *
  41.  *  Returns:        result of driver call to Stop
  42.  *                    normally 0, but could have parameter error or
  43.  *                    other error if non-existent block is specified
  44.  *
  45.  *  Side Effects:
  46.  *
  47.  *  Description:    We need three parameters or no parameters:
  48.  *                    1) the minute
  49.  *                    2) the second
  50.  *                    3) the block
  51.  *                    Get the famous global ioRefNum (set by CDOpen())
  52.  *                    Extract the minute, second and block and set a
  53.  *                    stop at that point.  If we aren't passed any
  54.  *                    parameters, set the stop at the end of the disc and
  55.  *                    search to the beginning of the disc.
  56.  *
  57.  ************************************************************************/
  58. pascal void
  59. CDStop(paramPtr)
  60. XCmdBlockPtr    paramPtr;
  61. {
  62.     Str31    returnString;
  63.     OSErr    result;
  64.     long    minute;
  65.     long    second;
  66.     long    block;
  67.     short    ioRefNum;
  68.     Handle    refHandle;
  69.     
  70.     /* Must be no parameters, or three parameters */
  71.     if ((paramPtr->paramCount) != 0)
  72.     {
  73.         if ((paramPtr->paramCount) != 3)
  74.         {
  75.             /* Report error in parameters by returning -1 */
  76.             NumToStr(paramPtr, (long) -1, &returnString);
  77.             paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  78.             return;
  79.         }
  80.     }
  81.     
  82.     /* Get the global ioRefNum and convert it. */
  83.     refHandle = GetGlobal(paramPtr, GLOBALNAME);
  84.     ioRefNum = atoi(*(refHandle));
  85.     DisposHandle(refHandle);
  86.     ioRefNum &= 0xFFFF;            /* remove vRefNum; not needed. */
  87.     
  88.     result = noErr;
  89.     
  90.     if ((paramPtr->paramCount) == 0)
  91.     {
  92.         result = DiscTime(ioRefNum, &minute, &second, &block);
  93.         if (result == noErr)
  94.         {
  95.             TimeDiff(&minute, &second, &block, minute, second, block, 0L, 0L, 1L);
  96.             result = AStop(paramPtr, ioRefNum, minute, second, block);
  97.         }
  98.         if (result == noErr)    /* search to 1st track */
  99.             result = TrackStart(ioRefNum, 1, &minute, &second, &block);
  100.         if (result == noErr)
  101.             result = ASearch(paramPtr, ioRefNum, 0, minute, second, block);
  102.     
  103.     }
  104.     else
  105.     {
  106.         /* First param is minute.  Convert it to a BCD number */
  107.         ExtractBCD((char *)*(paramPtr->params[0]), &minute);
  108.         
  109.         /* Second param is second.  Convert it to a BCD number */
  110.         ExtractBCD((char *)*(paramPtr->params[1]), &second);
  111.         
  112.         /* Third param is block.  Convert it to a BCD number */
  113.         ExtractBCD((char *)*(paramPtr->params[2]), &block);
  114.  
  115.         minute = BCD2DECIMAL(minute);
  116.         second = BCD2DECIMAL(second);
  117.         block = BCD2DECIMAL(block);
  118.         result = AStop(paramPtr, ioRefNum, minute, second, block);
  119.     }
  120.     
  121.     
  122.     /* Convert result to string & return it */
  123.     NumToStr(paramPtr, (long) result, &returnString);
  124.     paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  125. }
  126.  
  127. /************************************************************************
  128.  *
  129.  *  Function:        ExtractBCD
  130.  *
  131.  *  Purpose:        Extract number in BCD from PString
  132.  *
  133.  *  Returns:        nothing
  134.  *
  135.  *  Side Effects:    *track gets a new value
  136.  *
  137.  *  Description:    Extract number in BCD from Cstring "name".
  138.  *                    "name" is always of the form "XX", where XX
  139.  *                    ranges from "1"  to "99"
  140.  *
  141.  ************************************************************************/
  142. void
  143. ExtractBCD(name, number)
  144. char        *name;
  145. long        *number;
  146. {
  147.     long    t;
  148.         
  149.     t = 0;
  150.     while (*name != 0)
  151.     {
  152.         t *= 16;
  153.         t += *name - '0';
  154.         name++;
  155.     }
  156.     
  157.     *number = t;    
  158. }
  159.  
  160. /************************************************************************
  161.  *
  162.  *  Function:        AStop
  163.  *
  164.  *  Purpose:        stop playing at an absolute minute, second, block
  165.  *
  166.  *  Returns:        OSErr.  Probably either
  167.  *                        noErr        everything's hunky-dory!
  168.  *                        paramErr    you messed up the call somehow.
  169.  *
  170.  *  Side Effects:    stops play.
  171.  *
  172.  *  Description:    pass in the absolute minute, second and block in BCD.
  173.  *
  174.  ************************************************************************/
  175. OSErr
  176. AStop(paramPtr, refNum, minute, second, block)
  177. XCmdBlockPtr    paramPtr;
  178. short    refNum;
  179. long    minute;
  180. long    second;
  181. long    block;
  182. {
  183.     CDPlayParam    myPB;
  184.     short        playMode;
  185.     Handle        refHandle;
  186.     OSErr        result;
  187.     
  188.     /* Get the global ioRefNum and convert it. */
  189.     refHandle = GetGlobal(paramPtr, PLAYMODE);
  190.     playMode = atoi(*(refHandle));
  191.     DisposHandle(refHandle);
  192.     
  193.     myPB.ioCompletion = 0;
  194.     myPB.ioNamePtr = (char *) 0;
  195.     myPB.ioVRefNum = 1;
  196.     myPB.ioCRefNum = refNum;
  197.     myPB.csCode = ASTOP;
  198.     
  199.     myPB.addrFormat = AMSFADDR;
  200.     myPB.unused = 0;
  201.     myPB.minute = (char) DECIMAL2BCD(minute);    /* must be in BCD */
  202.     myPB.second = (char) DECIMAL2BCD(second);    /* must be in BCD */
  203.     myPB.block = (char) DECIMAL2BCD(block);        /* must be in BCD */
  204.     myPB.stopAddress = 0;
  205.     myPB.playMode = playMode;
  206.     result = PBControl(&myPB, false);
  207.     return result;
  208. }
  209.  
  210.  
  211.  
  212. /************************************************************************
  213.  *
  214.  *  Function:        ASearch
  215.  *
  216.  *  Purpose:        start Searching at an absolute minute, second, block
  217.  *
  218.  *  Returns:        OSErr.  Probably either
  219.  *                        noErr        everything's hunky-dory!
  220.  *                        paramErr    you messed up the call somehow.
  221.  *
  222.  *  Side Effects:    positions CD at the specified location and pauses or
  223.  *                    plays, depending upon flag.  0 = pause, 1 = play.
  224.  *
  225.  *  Description:    pass in the absolute minute, second and block in BCD.
  226.  *
  227.  ************************************************************************/
  228. OSErr
  229. ASearch(paramPtr, refNum, flag, minute, second, block)
  230. XCmdBlockPtr    paramPtr;
  231. short    refNum;
  232. short    flag;        /* 0 = pause, 1 = play. */
  233. long    minute;
  234. long    second;
  235. long    block;
  236. {
  237.     CDParam    myPB;
  238.     short        playMode;
  239.     Handle        refHandle;
  240.     
  241.     /* Get the global ioRefNum and convert it. */
  242.     refHandle = GetGlobal(paramPtr, PLAYMODE);
  243.     playMode = atoi(*(refHandle));
  244.     DisposHandle(refHandle);
  245.     
  246.     myPB.ioCompletion = 0;
  247.     myPB.ioNamePtr = (char *) 0;
  248.     myPB.ioVRefNum = 1;
  249.     myPB.ioCRefNum = refNum;
  250.     myPB.csCode = ASEARCH;
  251.     
  252.     myPB.csParam[0] = 0;
  253.     myPB.csParam[1] = AMSFADDR;
  254.     myPB.csParam[2] = 0;            /* must be in BCD */
  255.     myPB.csParam[3] = (char) DECIMAL2BCD(minute);    /* must be in BCD */
  256.     myPB.csParam[4] = (char) DECIMAL2BCD(second);    /* must be in BCD */
  257.     myPB.csParam[5] = (char) DECIMAL2BCD(block);    /* must be in BCD */
  258.     myPB.csParam[6] = 0;
  259.     myPB.csParam[7] = flag;
  260.     myPB.csParam[8] = 0;
  261.     myPB.csParam[9] = playMode;
  262.     return (PBControl(&myPB, false));
  263. }
  264.  
  265.  
  266. /* C routines for HyperCard callbacks */
  267. #include <XCmdGlue.inc.c>
  268.